package boke;

public class StringLei {
    public static void main1(String[] args) {
//        final char[] str={'1','2','3'};
//        str[0]='4';
//        final int a=3;
//        System.out.println(str);
//        String s1="wqe";
//        String s2=new String("wqer");
//        char[] str={'w','q','e'};
//        String s3=new String(s2);
//        System.out.println(s1);
//        System.out.println(s2);
//        System.out.println(s3);
        String q1="abc";
        String q2="abcA";
        String q3="abZ";
        String q4="abc";
        String q5=q1;
        //==比较地址
        System.out.println(q1 == q5);
        System.out.println(q1 == q3);
        System.out.println(q1 == q2);
        System.out.println("===========");
        //equals方法比较值
        System.out.println(q1.equals(q5));
        System.out.println(q1.equals(q3));
        System.out.println(q1.equals(q2));
        //compareTo桉顺序比较，不同返回差值,如果字符串长度不一样，而返回-1或者1
        System.out.println("===========");
        System.out.println(q1.compareTo(q4));
        System.out.println(q2.compareTo(q1));
        System.out.println(q1.compareTo(q3));
    }

    public static void main2(String[] args) {
        String s="abcabcabcqwertyuiopz";
        System.out.println(s.charAt(3));//a
        System.out.println(s.indexOf('a'));//0
        System.out.println(s.indexOf('a', 3));//3
        System.out.println(s.indexOf("cab"));//2
        System.out.println(s.indexOf("cab", 5));//5
        System.out.println(s.lastIndexOf(3));//-1(没有找到)
        System.out.println(s.lastIndexOf("a", 10));//6
        System.out.println(s.lastIndexOf("cabc"));//5
        System.out.println(s.lastIndexOf("cabc",7));//5
    }

    public static void main3(String[] args) {
        //数字转字符串(通过String.valueOf)
        String s1=String.valueOf(1234);
        String s2=String.valueOf(12.34);
        String s3=String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println("============");
        int data1=Integer.parseInt("1234");
        int data2=Integer.parseInt("12534");
        System.out.println(data1);
        System.out.println(data2);
    }

    public static void main4(String[] args) {
        String q1="qwe";
        String q2="QWE";
        System.out.println(q1.toUpperCase());
        System.out.println(q1.toLowerCase());
    }

    public static void main5(String[] args) {
        String w1="qwerty";
        //字符串转数组
        char[] ch= w1.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            System.out.println(ch[i]);
        }
        System.out.println();
        //数组转字符串
        String s2=new String(ch);
        System.out.println(s2);
    }

    public static void main6(String[] args) {
        String e1=String.format("%d-%d-%d",2019,9,14);
        System.out.println(e1);
    }

    public static void main(String[] args) {
        //StringBuffer sbd="qwe";//会报错
        StringBuilder sbd=new StringBuilder("wqwq");
        StringBuffer sbf=new StringBuffer("asd");

        System.out.println(sbd);
        System.out.println(sbf);
    }
}
